package com.service.impl;


import com.mapper.PowerMapper;
import com.pojo.Power;
import com.service.PowerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class PowerServiceImpl implements PowerService {

    @Autowired
    private PowerMapper powerMapper;
    @Override
    public List<Power> selectAllPowers() {
        return powerMapper.selectAllPowers();
    }

    @Override
    public List<Power> selectPowers() {
        return powerMapper.selectPowers();
    }

    @Override
    public List<Power> selectPowersByAdminId(long admin_id) {
        return powerMapper.selectPowersByAdminId(admin_id);
    }

    @Override
    public List<Power> selectPowersByRole_id(long role_id) {
        List<Power> powers = powerMapper.selectPowerOneByRid(role_id);
        for (int i=0;i<powers.size();i++){
            Power power = powers.get(i);
            List<Power> powers1 = powerMapper.selectPowerTwoByRidPid(role_id, power.getId());
            power.setPowers(powers1);
        }
        return powers;
    }
}
